package com.qcby.chatservice.web.domain;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 登录用户持有人
 *
 * @author cong.zhen
 * @date 2023/01/29
 */
public class LoginUserHolder {
    private static final ThreadLocal<CaLoginUser> LONGIN_USER_HOLDER = new ThreadLocal<CaLoginUser>();

    /**
     * set holder中内容
     *
     * @author cong.zhen
     * @date 2023/01/29
     */
    public static void set(CaLoginUser abstractLoginUser) {
        LONGIN_USER_HOLDER.set(abstractLoginUser);
    }

    /**
     * 获取holder中的值
     *
     * @author cong.zhen
     * @date 2023/01/29
     */
    public static CaLoginUser get() {
        return LONGIN_USER_HOLDER.get();
    }

    /**
     * 获得账户名称
     * @author cong.zhen
     * @date 2023/01/29
     */
    public static String getAccount() {
        CaLoginUser caLoginUser = LONGIN_USER_HOLDER.get();
        if (ObjectUtil.isNull(caLoginUser)) {
            return StrUtil.EMPTY;
        }
        return caLoginUser.getAccount();
    }

    /**
     * 得到真实姓名
     *
     * @author cong.zhen
     * @date 2023/01/29
     */
    public static String getRealName() {
        CaLoginUser caLoginUser = LONGIN_USER_HOLDER.get();
        if (ObjectUtil.isNull(caLoginUser)) {
            return StrUtil.EMPTY;
        }
        return caLoginUser.getRealName();
    }

    /**
     * 删除保存的用户
     *
     * @author cong.zhen
     * @date 2023/01/29
     */
    public static void remove() {
        LONGIN_USER_HOLDER.remove();
    }
}
